package com.web.base.open.dao;

import com.blue.jdbc.BaseDao;
import com.web.base.open.model.Account;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 开放平台帐号数据库访问
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年02月27日
 */
@Repository("openAccountDao")
public class AccountDao extends BaseDao<Account>
{
	public AccountDao()
	{
	}
	
	@Override
	protected void query(StringBuilder sql, Account param)
	{
		if (param != null)
		{
			if (param.getName() != null && !param.getName().isEmpty())
			{
				sql.append(" and a.name like :name");
				param.setName("%" + param.getName() + "%");
			}
			
			if (param.getState() != null)
				sql.append(" and a.state=:state");
				
		}
		sql.append(" order by a.id");
	}
	
	public String getSecret(String name)
	{
		String sql = "select secret from open_account where name=?";
		List<String> list = jdbcTemplate.queryForList(sql, String.class, name);
		if (list ==  null || list.isEmpty())
			return null;
		
		return list.get(0);
	}
	
}
